'use strict'

const BaseController = require('./base')

class DistrictController extends BaseController {
  constructor(ctx) {
    super(ctx, 'district')
  }
  async tree() {
    const { ctx } = this
    const list = await ctx.service[this.serviceName].tree(this.getListQuery(this.ctx.query))
    ctx.success(list)
  }
  getListQuery(query) {
    const { name } = query
    const where = {}
    if (name) {
      where.name = {
        [this.app.Sequelize.Op.like]: `%${name}%`
      }
    }
    return where
  }
}

module.exports = DistrictController
